use ffmpeg_sys_next::{
    AVDictionary, AVFormatContext, AVInputFormat, av_dump_format, avformat_alloc_context,
    avformat_close_input, avformat_find_stream_info, avformat_open_input, avformat_seek_file,
};
use std::ffi::{c_char, c_int};

pub fn avformat_alloc_context_safe() -> *mut AVFormatContext {
    unsafe { avformat_alloc_context() }
}

pub fn avformat_open_input_safe(
    ps: *mut *mut AVFormatContext,
    url: *const c_char,
    fmt: *const AVInputFormat,
    options: *mut *mut AVDictionary,
) -> c_int {
    unsafe { avformat_open_input(ps, url, fmt, options) }
}

pub fn avformat_find_stream_info_safe(
    ic: *mut AVFormatContext,
    options: *mut *mut AVDictionary,
) -> c_int {
    unsafe { avformat_find_stream_info(ic, options) }
}

pub fn av_dump_format_safe(
    ic: *mut AVFormatContext,
    index: c_int,
    url: *const c_char,
    is_output: c_int,
) {
    unsafe { av_dump_format(ic, index, url, is_output) }
}

pub fn avformat_close_input_safe(s: *mut *mut AVFormatContext) {
    unsafe { avformat_close_input(s) }
}

pub fn avformat_seek_file_safe(
    s: *mut AVFormatContext,
    stream_index: c_int,
    min_ts: i64,
    ts: i64,
    max_ts: i64,
    flags: c_int,
) -> c_int {
    unsafe { avformat_seek_file(s, stream_index, min_ts, ts, max_ts, flags) }
}
